home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / pack / xpk_Source.lha / xpk_Source / xpkmaster / query.c < prev    next >
C/C++ Source or Header  |  1998-03-27  |  5KB  |  189 lines

  1. #ifndef XPKMASTER_QUERY_C
  2. #define XPKMASTER_QUERY_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        query.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: query.c 1.10 (26.03.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Implementation of XpkQuery
  12.  
  13.  1.0   06.10.96 : first real version
  14.  1.1   27.12.96 : removed 1.3 specific functions
  15.  1.2   09.03.97 : added USER mode
  16.  1.3   31.03.97 : made tag processing better, nearly rewritten all, removed
  17.      goto's this way
  18.  1.4   09.06.97 : fixed Enforcer hit, when library opening failed
  19.  1.5   19.12.97 : code cleanup
  20.  1.6   24.12.97 : no packmode brings default mode now
  21.  1.7   01.01.98 : USER information is a bit better now
  22.  1.8   21.02.98 : uses new style register definition
  23.  1.9   03.03.98 : fixed enforcer hits
  24.  1.10  26.03.98 : some optimizations
  25. */
  26.  
  27. #include <exec/memory.h>
  28. #include <proto/exec.h>
  29. #include <proto/dos.h>
  30. #include <proto/xpksub.h>
  31. #include <proto/utility.h>
  32. #include "xpkmaster.h"
  33. #include "texts.h"
  34.  
  35. /************************************************************************
  36.  *
  37.  *  Information query
  38.  *
  39.  */
  40.  
  41. static const struct XpkMode USERMode = { 0,100,0,0,0,50,500,500,0,"user"};
  42.  
  43. static const struct XpkInfo USERInfo = { 1,0,0,1,"USER","User",
  44. 0, 0x55534552, XPKIF_PK_CHUNK|XPKIF_UP_CHUNK, DEFAULTCHUNKSIZE, 10,
  45. DEFAULTCHUNKSIZE,0,0,0,0,100,0,&USERMode,0,0,0,0,0,0};
  46.  
  47. ASM(LONG) LIBXpkQuery(REG(a0, struct TagItem *tags))
  48. {
  49.   struct TagItem    *ti, *ti2 = tags;
  50.   ULONG            packmode = 101,
  51.             packmethod = 0,
  52.               prefs = 1; /* use prefs, default is true */
  53.   LONG            error = 0;
  54.   struct XpkPackerInfo *pinfo = 0;
  55.   struct XpkPackerList *plist = 0;
  56.   struct XpkMode *    pmode = 0;
  57.   struct Library *    XpkSubBase = 0;
  58.   struct XpkInfo *    sinfo = 0;
  59.   UBYTE            libname[SUBLIBNAME_SIZE];
  60.  
  61. #ifdef DEBUG
  62.   DebugTagList("XpkQuery", tags);
  63. #endif
  64.  
  65.   while((ti = NextTagItem(&ti2)))
  66.   {
  67.     switch(ti->ti_Tag)
  68.     {
  69.     case XPK_PackersQuery: plist = (struct XpkPackerList *) ti->ti_Data;
  70.       break;
  71.     case XPK_ModeQuery: pmode = (struct XpkMode *) ti->ti_Data; break;
  72.     case XPK_PackerQuery: pinfo = (struct XpkPackerInfo *) ti->ti_Data;
  73.       break;
  74.     case XPK_PackMethod: packmethod = idfromname((STRPTR) ti->ti_Data);
  75.       break;
  76.     case XPK_PackMode: packmode = ti->ti_Data; break;
  77.     case XPK_Preferences: prefs = ti->ti_Data; break;
  78.     }
  79.   }
  80.  
  81.   if(plist)
  82.   {
  83.     struct FileInfoBlock *fib;
  84.  
  85.     if(!(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)))
  86.       error = XPKERR_NOMEM;
  87.     else
  88.     {
  89.       ULONG lock;
  90.  
  91.       memset(plist, 0, sizeof(struct XpkPackerList));
  92.       if(!(lock = Lock("LIBS:compressors", ACCESS_READ)))
  93.         error = XPKERR_NOINFO;
  94.       else
  95.       {
  96.         if(!Examine(lock, fib) || fib->fib_DirEntryType < 0)
  97.           error = XPKERR_NOINFO;
  98.         else
  99.         {
  100.       while(ExNext(lock, fib))
  101.       {
  102.         if(!strncmp("xpk", fib->fib_FileName, 3) &&
  103.             !strcmp(".library", fib->fib_FileName+7))
  104.         {
  105.           ULONG ID = idfromname(fib->fib_FileName+3), i;
  106.  
  107.               for(i = plist->xpl_NumPackers; i > 0 &&
  108.           *(ULONG *) plist->xpl_Packer[i - 1] > ID; i--)
  109.           *(ULONG *) plist->xpl_Packer[i] =
  110.           *(ULONG *) plist->xpl_Packer[i-1];
  111.           *(ULONG *) plist->xpl_Packer[i] = ID;
  112.  
  113.           if(++plist->xpl_NumPackers == MAXPACKERS)
  114.             break;
  115.         }
  116.       }
  117.           if(prefs) /* add USER mode */
  118.           {
  119.         if(plist->xpl_NumPackers == MAXPACKERS)
  120.           --plist->xpl_NumPackers;
  121.             *(ULONG *) plist->xpl_Packer[plist->xpl_NumPackers++] = 0x55534552;
  122.           }
  123.         }
  124.         UnLock(lock);
  125.       }
  126.       FreeDosObject(DOS_FIB, fib);
  127.     }
  128.   }
  129.   else if(packmethod)
  130.   {
  131.     if(packmethod == USER_COOKIE)
  132.     {
  133.       sinfo = (struct XpkInfo *) &USERInfo;
  134.       sinfo->xi_Description = strings[TXT_USER_DESCRIPTION];
  135.     }
  136.     else
  137.     {
  138.       sprintf(libname, SUBLIBNAME_STRING, &packmethod);
  139.  
  140.       if(!(XpkSubBase = OpenLibrary(libname, 0)) ||
  141.       !(sinfo = XpksPackerInfo()))
  142.         error = XPKERR_MISSINGLIB;
  143.     }
  144.     
  145.     if(!error)
  146.     {
  147.       if(pinfo)
  148.       {
  149.         sprintf(pinfo->xpi_Name, sinfo->xi_Name);
  150.         sprintf(pinfo->xpi_LongName, sinfo->xi_LongName);
  151.         sprintf(pinfo->xpi_Description, sinfo->xi_Description);
  152.         pinfo->xpi_Flags = sinfo->xi_Flags;
  153.         pinfo->xpi_MaxChunk = sinfo->xi_MaxPkInChunk;
  154.         pinfo->xpi_DefChunk = sinfo->xi_DefPkInChunk;
  155.         pinfo->xpi_DefMode = sinfo->xi_DefMode;
  156.       }
  157.       else if(pmode)
  158.       {
  159.         struct XpkMode* m = sinfo->xi_ModeDesc;
  160.  
  161.         if(packmode == 101)
  162.           packmode = sinfo->xi_DefMode;
  163.  
  164.         while(m && m->xm_Upto < packmode)
  165.           m = m->xm_Next;
  166.  
  167.         if(m)
  168.         {
  169.           CopyMem(m, pmode, sizeof(struct XpkMode));
  170.           pmode->xm_Next = 0;
  171.         }
  172.         else
  173.           error = XPKERR_NOINFO;
  174.       }
  175.       else
  176.         error = XPKERR_BADPARAMS;
  177.     }
  178.     if(XpkSubBase)
  179.       CloseLibrary(XpkSubBase);
  180.   }
  181.   else
  182.     error = XPKERR_BADPARAMS;
  183.  
  184.   return parseerrortags(tags, error);
  185. }
  186.  
  187. #endif /* XPKMASTER_QUERY_C */
  188.  
  189.